#include "gtest/gtest.h"
#include "watermarking/textwatermarkgenerator.h"
#include "watermarking/watermarkgeneratorfactory.h"

class TestWhitespaceWatermarkGenerator : public ::testing::Test
{
protected:
	void SetUp()
	{
		m_factory = new Wishmaster::WatermarkGeneratorFactory();
	}

	void TearDown()
	{
		delete m_factory;
		m_factory = 0;
	}

	void testEmpty();
	void testCasting();

	Wishmaster::WatermarkGeneratorFactory* m_factory;
};

TEST_F(TestWhitespaceWatermarkGenerator, Empty)
{
	Wishmaster::TextWatermarkGeneratorPtr generator = m_factory->createTextWatermark("whitespace");
	QString initial = "Foo bar";
	QString result = generator->cast(initial, QByteArray());
	ASSERT_EQ(0, initial.compare(result));
}

TEST_F(TestWhitespaceWatermarkGenerator,Casting)
{
	Wishmaster::TextWatermarkGeneratorPtr generator = m_factory->createTextWatermark("whitespace");
	QString initial = "";
	QByteArray watermark;
	watermark.append((char)0x00);
	watermark.append((char)0x01);
	watermark.append((char)0x42);
	QString result = generator->cast(initial, watermark);

	ASSERT_EQ(14, result.size());
	ASSERT_EQ((unsigned short)0x2800, result.at(0).unicode());
	ASSERT_EQ((unsigned short)0x2800, result.at(13).unicode());

	ASSERT_TRUE(generator->probe(result));

	QByteArray w2 = generator->decode(result);
	ASSERT_EQ(3, w2.size());
	ASSERT_EQ((int)0x00, (int)w2.at(0));
	ASSERT_EQ((int)0x01, (int)w2.at(1));
	ASSERT_EQ((int)0x42, (int)w2.at(2));
}
